import { defineStore } from "pinia";
import { Names } from "../../store-namespace";
import { _get, _post, _put, _delete, http } from "@/utils/axios";
import { DeviceModel } from "@/api/backend/index";
import { ElNotification } from "element-plus"; //处理导航信息

export const useModel = defineStore(Names.Model, {
  state: () => {
    return {
      single: {},
      modelList: [],
      modelMap: new Map(),
    };
  },
  getters: {},
  actions: {
    //获取相应型号数据
    getSingleInfo(data: any) {
      return new Promise((resolve, reject) => {
        _get(DeviceModel + "/list", data, "json", "")
          .then((res) => {
            console.log("获取相应型号数据", res);
            resolve(res);
          })
          .catch((err) => {
            console.log(err);
          });
      });
    },
    //获取设备类型列表
    getList(filter: any) {
      return new Promise((resolve, reject) => {
        _get(DeviceModel + "/list", filter, "", "")
          .then(async (res: any) => {
            console.log("获取设备类型列表", res);
            this.modelList = res.rows; //将数据保存在state中
            // this.modelMap = await mapCompanies(res); //将数据变成Map数据格式
            resolve(res);
          })
          .catch((err) => {
            reject(err);
          });
      });
    },
  },
});
